import typing
import sys
from PyQt5.QtCore import Qt
from PyQt5.QtWidgets import QApplication, QMainWindow, QMdiSubWindow
from PyQt5 import QtCore

sys.path.append("..")
from Ui_mainWindow import Ui_GNSS
from loadLog.loadLogWindow import LoadLogSubWindow


class MainWindow(QMainWindow):
    def __init__(self, parent=None) -> None:
        self.worker = {}
        self.worker_factory = {"": ""}
        super().__init__(parent=parent)
        self.__ui = Ui_GNSS()
        self.__ui.setupUi(self)
        self.setStartUi()

    def setStartUi(self):
        self.__ui.treeWidget.expandAll()
        self.l = LoadLogSubWindow(self.__ui.mdiArea)
        self.l.close_signal.connect(self.close_subWindow)

    def close_subWindow(self, subWindow):
        self.l.hide()
        print("close subWindows: " + subWindow)

    def onShowSelectWorkerDock(self):
        self.__ui.workerSelectDockWidget.setVisible(
            self.__ui.action_show_worker_tree.isChecked()
        )

    def onWorkerSelectDockVisibilityChanged(self):
        self.__ui.action_show_worker_tree.setChecked(
            self.__ui.workerSelectDockWidget.isVisible()
        )

    def onWorkerCheckedChanged(self, item, cloumn):
        if item.text(0) == "Loding Host Log":
            if item.checkState(cloumn) == Qt.Checked:
                self.l.show()
            elif item.checkState(cloumn) == Qt.Unchecked:
                self.l.hide()


if __name__ == "__main__":
    app = QApplication(sys.argv)
    m = MainWindow()
    m.show()
    sys.exit(app.exec_())